function btoa(t) {
  for (var i, e = String(t), n = 0, o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", s = ""; e.charAt(0 | n) || (o = "=", n % 1); s += o.charAt(63 & i >> 8 - n % 1 * 8)) i = i << 8 | e.charCodeAt(n += .75);
  return s;
}
function atob(t) {
  var i = String(t).replace(/[=]+$/, "");
  i.length;
  for (var e, n, o = 0, s = 0, a = ""; n = i.charAt(s++); ~n && (e = o % 4 ? 64 * e + n : n, o++ % 4) ? a += String.fromCharCode(255 & e >> (-2 * o & 6)) : 0) n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);
  return a;
}
!function () {
  if (!window || !window.tt) return void console.log("error plat", window);
  var t = {
    registerHandler: function registerHandler(t) {
      this.data ? t(this.data) : (this.config.parse = t, this.parse = t);
    },
    init: function init(t) {
      var _this = this;
      this.config = t, this.config.api_url = "https://oppomini.eqmobi.com/toutiao/" + this.config.EQAPPKEY + "/" + this.config.EQVERSION + "/api", this.config.login_url = "https://oppomini.eqmobi.com/toutiao/" + this.config.EQAPPKEY + "/" + this.config.EQVERSION + "/login", this.config.enable = !1, this.config.savedir = "", this.config.ver = 3, this.savefuc = tt.setStorage, this.loadfuc = tt.getStorage, this.netpost = tt.request, this.parse = t.parse, this.onLoginned = t.onLoginned, this.showuserbuttonfunc = tt.createUserInfoButton;
      try {
        tt.onNavigateToMiniProgram && tt.onNavigateToMiniProgram(function (t) {
          switch (t.errCode) {
            case 0:
              _this.sendevent("跳转成功回调", t);
              break;
            case 1:
              _this.sendevent("跳转失败", t);
              break;
            case 2:
              _this.sendevent("跳转取消", t);
          }
        });
      } catch (e) {}
      this.config.launcheroption = tt.getLaunchOptionsSync(), this.config.sysinfo = tt.getSystemInfoSync(), this.config.envinfo = tt.getEnvInfoSync(), tt.eqSendEvent = function (t, i) {
        var e = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
        _this.sendevent(t, i, e);
      }, tt.eqSaveData = function (t) {
        var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
        _this.savedata(t, i);
      }, tt.eqGetData = function () {
        var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
        var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
        _this.getdata(t, i);
      }, tt.eqLogin = function (t) {
        _this.eqlogin(t);
      }, tt.eqRegisterHandler = function (t) {
        _this.registerHandler(t);
      }, tt.eqGetConfig = function () {
        return _this.config;
      }, tt.eqTouch = function (t) {
        _this.touch(t);
      }, tt.onAppShow && tt.onAppShow(function (t) {
        _this.onShow(t);
      }), tt.onAppHide && tt.onAppHide(function (t) {
        _this.onHide(t);
      }), tt.onShow && tt.onShow(function (t) {
        _this.onShow(t);
      }), tt.onHide && tt.onHide(function (t) {
        _this.onHide(t);
      }), tt.onError(function (t, i) {
        _this.d("onError", t), _this.onError(t, i);
      });
      var i = function i() {
        _this.d("need login"), _this.login({
          skipuserinfo: !0,
          success: function success() {
            _this.onLoginned && _this.onLoginned(_this.config.userinfo);
          },
          fail: function fail() {}
        });
      };
      try {
        this.d("ready load");
        var _t = tt.getStorageSync("eq4096user.json");
        this.d("load ==", _t), _t ? (this.d("local read", _t), this.config.userinfo = _t, _t.openId && "" != _t.openId ? (this.d("skip login"), _t.userinfo && "string" == typeof _t.userinfo && (this.config.userinfo.userinfo = JSON.parse(_t.userinfo)), this.onLoginned && this.onLoginned(this.config.userinfo)) : i()) : i();
      } catch (n) {
        this.d("check login error", n), i();
      }
      this.syncdata();
    },
    sendevent: function sendevent(t, i) {
      var _this2 = this;
      var e = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
      var n = this.config;
      n.skip_event && n.skip_event.indexOf(t) >= 0 || this.netpost({
        url: this.config.api_url,
        method: "POST",
        dataType: "json",
        data: {
          event: {
            key: t,
            obj: i
          },
          config: n
        },
        success: function success(t) {
          var i = t.data;
          _this2.net_callback(i, e);
        },
        fail: function fail(t) {
          _this2.d("syncdata err=", t);
        }
      });
    },
    net_callback: function net_callback(t, i) {
      if (this.d("net_callback=", t, i), t.data && t.data.eqop && this[t.data.eqop]) {
        var _i = t.data[t.data.eqop];
        (0, this[t.data.eqop]).apply(void 0, babel_toConsumableArray(_i));
      }
      if (t.data && t.data.op && tt[t.data.op]) {
        var _i2 = t.data[t.data.op];
        (0, tt[t.data.op]).apply(void 0, babel_toConsumableArray(_i2));
      }
      !t.skip_parse && i && i(t);
    },
    codelogin: function codelogin(t) {
      var _this3 = this;
      this.d(t), this.config.puserinfo = t.puserinfo, this.d(this.config), this.netpost({
        method: "POST",
        dataType: "json",
        url: this.config.login_url,
        data: this.config,
        success: function success(i) {
          if (_this3.d(i), 0 == i.data.ret) {
            var e = i.data.data;
            if (e.openid && "" != e.openid && (e.openId = e.openid), e.userinfo && "string" == typeof e.userinfo && (e.userinfo = JSON.parse(e.userinfo)), tt.setStorageSync("eq4096user.json", e), _this3.config.userinfo = e, t.skipuserinfo) t.success(i.data);else {
              var _i3 = function _i3() {
                tt.getUserInfo({
                  withCredentials: !0,
                  success: function success(i) {
                    if (i.userInfo) {
                      Object.keys(i.userInfo);
                      for (var _t2 in i.userInfo) e[_t2] = i.userInfo[_t2];
                      e.orguserinfo = i, tt.setStorageSync("eq4096user.json", e), _this3.config.userinfo = e, t.success(e), _this3.sendevent("updateuserinfo", e);
                    } else t.fail && t.fail(i);
                  },
                  fail: function fail(i) {
                    t.fail && t.fail(i);
                  }
                });
              };
              tt.getSetting({
                success: function success(e) {
                  e.authSetting["scope.userInfo"] ? _i3() : tt.authorize({
                    scope: "scope.userInfo",
                    success: function success() {
                      _i3();
                    },
                    fail: function fail(i) {
                      t.fail && t.fail(i);
                    }
                  });
                },
                fail: function fail() {
                  _i3();
                }
              });
            }
          } else t.fail(i.data);
        },
        fail: function fail(i) {
          _this3.d(i), t.fail(i);
        }
      });
    },
    login: function login(t) {
      var _this4 = this;
      tt.login({
        force: !t.skipuserinfo,
        success: function success(i) {
          _this4.d(i), t.puserinfo = i, _this4.codelogin(t);
        },
        fail: function fail(i) {
          t.fail && t.fail(i);
        }
      });
    },
    eqlogin: function eqlogin(t) {
      var _this5 = this;
      t.success = t.success || function () {}, t.fail = t.fail || function () {}, t.createbutton = t.createbutton || function () {}, this.loadfuc({
        key: "eq4096user.json",
        success: function success(i) {
          if (i.data) {
            var e = i.data;
            e.openId && e.nickName ? (delete i.data.fromuserbutton, t.success(i.data)) : _this5.login(t);
          } else _this5.login(t);
        },
        fail: function fail() {
          _this5.login(t);
        }
      });
    },
    setuserinfo: function setuserinfo(t) {
      if (this.config.userinfo) {
        for (var i in t) this.config.userinfo[i] = t[i];
        this.sendevent("updateuserinfo", this.config.userinfo);
      } else this.config.userinfo = t, this.sendevent("updateuserinfo", this.config.userinfo);
      this.d("local write", this.config.userinfo), tt.setStorageSync("eq4096user.json", this.config.userinfo);
    },
    getconfig: function getconfig() {
      return this.config;
    },
    d: function d(t, i) {
      this.config.debug && console.log(t, i);
    },
    onShow: function onShow(t) {
      this.config.start_res = t, this.sendevent("onShow", t), this.config.onShow && this.config.onShow(t);
    },
    onHide: function onHide(t) {
      this.sendevent("onHide", t), this.config.onHide && this.config.onHide(t);
    },
    onError: function onError(t) {
      this.config.error = {
        msg: t
      }, this.config.error = void 0, this.config.onError && this.config.onError(t);
    },
    touchend: function touchend() {
      this.touchflag = !0;
    },
    touch: function touch(t) {
      var _this6 = this;
      var i = t.success || function () {},
        e = t.fail || function () {};
      t.fail = function (i) {
        _this6.sendevent("跳转失败", t), e && e(i);
      }, t.success = function (e) {
        _this6.sendevent("跳转成功回调", t), i && i(e);
      }, tt[t.op](t);
    },
    syncdata: function syncdata() {
      var _this7 = this;
      this.netpost({
        method: "POST",
        dataType: "json",
        url: this.config.api_url,
        data: this.config,
        success: function success(t) {
          var i = t.data;
          _this7.net_callback(i, _this7.parseconfig.bind(_this7));
        },
        fail: function fail(t) {
          _this7.d("syncdata err=", t);
        }
      });
    },
    parseconfig: function parseconfig(t) {
      if (!t || !t.data || !this) return;
      var i = t.data;
      this.data = i, i.mergeconfig && (this.config = babel_objectSpread2(babel_objectSpread2({}, this.config), i.mergerconfig)), this.parse && this.parse(i);
    },
    savedata: function savedata(t, i) {
      var e = 0;
      this.config && this.config.userinfo && this.config.userinfo.id && (e = this.config.userinfo.id), 0 != e ? this.sendevent("modifyInteractiveStorage", this.code(babel_objectSpread2({
        key: "gamedata_".concat(this.config.userinfo.id)
      }, t)), i) : (this.d("savedata error id==0"), i({
        error: "id error",
        ret: -2
      }));
    },
    getdata: function getdata(t, i) {
      var _this8 = this;
      var e = 0;
      this.config && this.config.userinfo && this.config.userinfo.id && (e = this.config.userinfo.id), 0 != e ? this.sendevent("getInteractiveStorage", this.code(babel_objectSpread2({
        key: "gamedata_".concat(this.config.userinfo.id)
      }, t)), function (t) {
        if (_this8.d("get data before:", t), t.data) {
          var _e = _this8.decode(t.data);
          _this8.d("get data:", _e), i({
            ret: 0,
            data: _e
          });
        } else i({
          ret: -2,
          error: JSON.stringify(t)
        });
      }) : (this.d("getdata error id==0"), i({
        error: "id error",
        ret: -2
      }));
    },
    decode: function decode(t) {
      if (null == t) return null;
      {
        t = atob(t);
        var i = "";
        for (var e = 0; e < t.length; e++) i += String.fromCharCode(t.charCodeAt(e) + 32);
        return i = atob(i), JSON.parse(i);
      }
    },
    code: function code(t) {
      var i = btoa(JSON.stringify(t)),
        e = "";
      for (var n = 0; n < i.length; n++) e += String.fromCharCode(i.charCodeAt(n) - 32);
      return btoa(e);
    }
  };
  tt && !tt.eqapi && (tt.eqapi = t);
}();